package thread;

import java.util.*;

public class SyncAPIDemo2 {
    public static void main(String[] args) {
        List<Integer> list = Collections.synchronizedList(new ArrayList<>());
//        List<Integer> list = new LinkedList<>();
//        Set<Integer> list = new HashSet<>();
        new Thread(()->{
                for(int i=0;i<1000;++i){
                list.add(i);
            }
        }).start();
        new Thread(()->{
                for(int i=0;i<1000;++i){
                list.add(i);
            }
        }).start();

        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(list.size());

    }
}
